<template>
    <div class="container">
        <div class="handle-box">
                <el-form ref="form" :model="form" label-width="80px" class="flex">
                    <el-form-item label="名称：">
                        <el-input v-model="name" placeholder="请输入名称" class="handle-input mr10" @input="mohu()"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" icon="el-icon-search" >搜索</el-button>
                    </el-form-item>
                    
                </el-form>
            </div>
            <el-table
                :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
            >
                <el-table-column prop="id" label="ID" width="55" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名"></el-table-column>
                <el-table-column prop="phone" label="手机号"></el-table-column>
                <el-table-column prop="area" label="负责区域名称"></el-table-column>
                <el-table-column prop="areaID" label="负责区域ID"></el-table-column>
                <el-table-column prop="IDcard" label="身份证号"></el-table-column>
                <el-table-column prop="authorization" label="授权码"></el-table-column>
                <el-table-column prop="webchatId" label="绑定微信"></el-table-column>
                <el-table-column prop="first" label="首次登陆时间"></el-table-column>
                <!-- <el-table-column label="兑换物品">
                    <template slot-scope="scope">{{scope.row.money}}</template>
                </el-table-column>
                <el-table-column prop="address" label="兑换类型"></el-table-column> -->
                <!-- <el-table-column label="状态" align="center">
                    <template slot-scope="scope">
                        <el-tag
                            :type="scope.row.state==='成功'?'success':(scope.row.state==='失败'?'danger':'')"
                        >{{scope.row.state}}</el-tag>
                    </template>
                </el-table-column> -->

                <!-- <el-table-column prop="date" label="兑换积分"></el-table-column> -->
                <!-- <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            icon="el-icon-edit"
                            @click="handleEdit(scope.$index, scope.row)"
                        >编辑</el-button>
                    </template>
                </el-table-column> -->
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, sizes, prev, pager, next, jumper"
                    :current-page="currentPage"  
                    :page-size="pageSize"
                    :total="tableData.length"
                    @size-change="handleSizeChange"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
            <!-- 编辑弹出框 -->
            <el-dialog v-dialogDrag title="编辑" :visible.sync="editVisible" width="30%">
                <el-form ref="form" :model="form" label-width="70px">
                    <el-form-item label="用户名：">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                    <el-form-item label="地址：">
                        <el-input v-model="form.address"></el-input>
                    </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="editVisible = false">取 消</el-button>
                    <el-button type="primary" @click="saveEdit">确 定</el-button>
                </span>
            </el-dialog>
        </div>
</template>
<script>
import '../../assets/css/common.css'

export default {
    data(){
        return{
              currentPage:1, //初始页
                pagesize:10,    //    每页的数据
                userList: [],
                address:'',
                name:'',
            tableData: [{
                id: '1',
                name:'张三',
                phone:'17568563456',
                area:'南开区',
                areaID:'5642',
                IDcard:'13556451351231564',
                authorization:'45465456',
                webchatId:'56563123',
                first: '2020-08-19 17:35:52',
            },{
                id: '2',
                name:'张三',
                phone:'17568563456',
                area:'南开区',
                areaID:'5642',
                IDcard:'13556451351231564',
                authorization:'45465456',
                webchatId:'56563123',
                first: '2020-08-19 17:35:52',
            },{
                 id: '3',
                name:'张三',
                phone:'17568563456',
                area:'南开区',
                areaID:'5642',
                IDcard:'13556451351231564',
                authorization:'45465456',
                webchatId:'56563123',
                first: '2020-08-19 17:35:52',
            },{
                id: '4',
                name:'张三',
                phone:'17568563456',
                area:'南开区',
                areaID:'5642',
                IDcard:'13556451351231564',
                authorization:'45465456',
                webchatId:'56563123',
                first: '2020-08-19 17:35:52',
            },{
                id: '5',
                name:'张三',
                phone:'17568563456',
                area:'南开区',
                areaID:'5642',
                IDcard:'13556451351231564',
                authorization:'45465456',
                webchatId:'56563123',
                first: '2020-08-19 17:35:52',
            },{
                id: '6',
                name:'张三',
                phone:'17568563456',
                area:'南开区',
                areaID:'5642',
                IDcard:'13556451351231564',
                authorization:'45465456',
                webchatId:'56563123',
                first: '2020-08-19 17:35:52',
            },{
                id: '7',
                name:'张三',
                phone:'17568563456',
                area:'南开区',
                areaID:'5642',
                IDcard:'13556451351231564',
                authorization:'45465456',
                webchatId:'56563123',
                first: '2020-08-19 17:35:52',
            }],
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0,
            form: {
                name: ''
            },
            idx: -1,
            id: -1
        }
    },
    created() {
        // this.getData();
    },
    methods: {
        // 获取 easy-mock 的模拟数据
        // getData() {
        //     fetchData(this.query).then(res => {
        //         console.log(res);
        //         this.tableData = res.list;
        //         this.pageTotal = res.pageTotal || 50;
        //     });
        // },
        // 触发搜索按钮
        // handleSearch() {
        //     this.$set(this.query, 'pageIndex', 1);
            // this.getData();
        // },
        // 模糊查询
        mohu() {
            var search = this.name;
            console.log(search)
            var newdate = [];
            if(search){
                if(search)
                 this.tableData.filter(item=>{
                    if(item.name.indexOf(search) != -1){
                        newdate.push(item)
                    }
                })
            }else if (search == ''){
                console.log(this.tableData)
            }
            this.tableData = newdate
        },
        // 编辑操作
        // handleEdit(index, row) {
        //     this.idx = index;
        //     this.form = row;
        //     this.editVisible = true;
        // },
        // 保存编辑
        saveEdit() {
            this.editVisible = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            this.$set(this.tableData, this.idx, this.form);
        },
        // 分页导航
        handlePageChange(currentPage) {
            this.currentPage = currentPage;
            // this.$set(this.query, 'pageIndex', val);
            // this.getData();
        },
        handleSizeChange(size){
            this.pagesize = size;
        }
    }
}
</script>
<style scoped>

</style>